how to input message ox in c#

76

how to input message ox in c# -

using System;
using Microsoft.VisualBasic;

namespace VisualBasic_Example
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create the input dialog box with the parameters below
            string input = Interaction.InputBox("What is at the end of the rainbow?", "Riddle", "...", 10, 10);
            
            //After the user has provided input, print to the console
            Console.WriteLine(input);
            Console.ReadLine();

        }
    }
}

how to input message ox in c# -

string input = Interaction.InputBox("Prompt", "Title", "Default", 10, 10);

how to input message ox in c# -

using System;
using System.Windows.Forms;
using System.Drawing;

namespace CustomDialog_Example
{
    class Program
    {
        static void Main(string[] args)
        {
            //Initialize the input variable which will be referenced by the custom input dialog box
            string input = "...";
            //Display the custom input dialog box with the following prompt, window title, and dimensions
            ShowInputDialogBox(ref input, "What is at the end of the rainbow?", "Riddle", 300, 200);

            //Print the input provided by the user
            Console.WriteLine(input);

            Console.ReadLine();

        }

        private static DialogResult ShowInputDialogBox(ref string input, string prompt, string title = "Title", int width = 300, int height = 200)
        {
            //This function creates the custom input dialog box by individually creating the different window elements and adding them to the dialog box

            //Specify the size of the window using the parameters passed
            Size size = new Size(width, height);
            //Create a new form using a System.Windows Form
            Form inputBox = new Form();

            inputBox.FormBorderStyle = FormBorderStyle.FixedDialog;
            inputBox.ClientSize = size;
            //Set the window title using the parameter passed
            inputBox.Text = title;

            //Create a new label to hold the prompt
            Label label = new Label();
            label.Text = prompt;
            label.Location = new Point(5, 5);
            label.Width = size.Width - 10;
            inputBox.Controls.Add(label);

            //Create a textbox to accept the user's input
            TextBox textBox = new TextBox();
            textBox.Size = new Size(size.Width - 10, 23);
            textBox.Location = new Point(5, label.Location.Y + 20);
            textBox.Text = input;
            inputBox.Controls.Add(textBox);

            //Create an OK Button 
            Button okButton = new Button();
            okButton.DialogResult = DialogResult.OK;
            okButton.Name = "okButton";
            okButton.Size = new Size(75, 23);
            okButton.Text = "&OK";
            okButton.Location = new Point(size.Width - 80 - 80, size.Height - 30);
            inputBox.Controls.Add(okButton);

            //Create a Cancel Button
            Button cancelButton = new Button();
            cancelButton.DialogResult = DialogResult.Cancel;
            cancelButton.Name = "cancelButton";
            cancelButton.Size = new Size(75, 23);
            cancelButton.Text = "&Cancel";
            cancelButton.Location = new Point(size.Width - 80, size.Height - 30);
            inputBox.Controls.Add(cancelButton);

            //Set the input box's buttons to the created OK and Cancel Buttons respectively so the window appropriately behaves with the button clicks
            inputBox.AcceptButton = okButton;
            inputBox.CancelButton = cancelButton;

            //Show the window dialog box 
            DialogResult result = inputBox.ShowDialog();
            input = textBox.Text;

            //After input has been submitted, return the input value
            return result;
        }

    }
}

how to input message ox in c# -

using Microsoft.VisualBasic;

Comments

Submit
0 Comments